﻿Type=Activity
Version=5.8
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.

End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.
	Private wvweb As WebView
	Private wvx As WebViewXtender
	Private wve As WebViewExtras
	Private wvurl As wvUrl
	Private lbltitle As Label
	Private pbar As ProgressBar
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	Activity.LoadLayout("laywebview")
	initviews
End Sub
Private Sub initviews
	wvurl=g_store.conf.Get("wvurl")
	If wvurl.IsInitialized Then
		wvweb.ZoomEnabled=wvurl.allowZoom
		wve.addWebChromeClient(wvweb,"wve")
		wvx.setJavaScriptEnabled(wvweb,True)
'		Dim jo As JavaObject 'api >23
'		jo=wvweb
'		Dim e As Object=jo.CreateEventFromUI("android.view.View.OnScrollChangeListener","osc",Null)
'		jo.RunMethod("setOnScrollChangeListener",Array As Object(e))
		If wvurl.Url.StartsWith("http") Then '自动加http前缀
			wvweb.LoadUrl(wvurl.Url)
		Else
			wvweb.LoadUrl("http://"&wvurl.Url)
		End If
		If wvurl.title.Length>1 Then lbltitle.Text=wvurl.title
	Else
		ToastMessageShow("网页调用对象未初始化错误",False)
		Activity.Finish
	End If
	
End Sub
'Sub osc_Event (MethodName As String, Args() As Object) As Object
'	Log($"MethodName:${MethodName} "$)
'	For i=0 To Args.Length-1
'		Log("i="&Args(i))
'	Next
'End Sub
Sub wve_GeolocationPermissionsRequest As Int
	Return wve.GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER
End Sub

Sub wve_ProgressChanged(NewProgress As Int)
	
End Sub
Sub Activity_Resume
	wvurl=g_store.conf.Get("wvurl")
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
	If KeyCode==KeyCodes.KEYCODE_BACK Then
		If CanGoBack(wvweb) Then
			'如果有历史地址就回退一下
			wvweb.Back
			Return True
		Else
			'否则退出
			Return False
		End If
	End If
	Return False
End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CanGoBack(wv As WebView) As Boolean
	 Dim r As JavaObject
	 r=wv
	 Return r.RunMethod("canGoBack",Array())
End Sub
Sub wvweb_PageFinished (Url As String)
	 Try
		 If wvurl.title.Length<1 Then
		 	Dim st As String=wvx.getTitle(wvweb)
			If st.Length>12 Then
				lbltitle.Text=st.SubString2(0,13)&"..."
			Else
				lbltitle.Text=st
			End If
		End If
	Catch
		Log(LastException.Message)
	End Try
	 pbar.Visible=False
End Sub

Sub wvweb_OverrideUrl (Url As String) As Boolean
	Log("loading_Url:"&Url)
	pbar.Visible=True
	Return False
End Sub
Sub ivback_Click
	Activity.Finish
End Sub